package com.weixiaodong.javabasic.Java中的枚举类型.后台用户角色管理.基于枚举实现的策略模式;

public enum CalEnum implements Operation{

    ADDITION {
        @Override
        public double excute(double x, double y) {
            return x + y;
        }
    },

    SUBTRACTION {
        @Override
        public double excute(double x, double y) {
            return x - y;
        }
    },

    MULTIPLICATION {
        @Override
        public double excute(double x, double y) {
            return x * y;
        }
    },

    DIVISION {
        @Override
        public double excute(double x, double y) {
            if (y == 0) {
                throw new ArithmeticException("by zero");
            }
            return x / y;
        }
    },
}
